﻿using System.Collections.Generic;

namespace GACore.Progress
{
	public class History
	{
		private List<HistoryEntry> entries = new List<HistoryEntry>();

		private Vector bestVector;
		public Vector BestOverallSolution
		{
			get { return bestVector; }
		}

		public void AddEntry(HistoryEntry entry)
		{
			SetBestVector(entry);
			entry.Step = entries.Count;
			entries.Add(entry);
		}

		private void SetBestVector(HistoryEntry entry)
		{
			if (bestVector == null || bestVector.CompareTo(entry.BestVector) > 0)
			{
				this.bestVector = entry.BestVector;
			}
		}

		public HistoryEntry this[int step]
		{
			get { return entries[step]; }
			set { entries[step] = value; }
		}

		public HistoryEntry Current
		{
			get { return entries[entries.Count - 1]; }
		}

	}
}
